package loader

import (
	"os"
	"path/filepath"
	"kumachan/interpreter/lang/textual/ast"
	"kumachan/interpreter/compiler/loader/manifest"
	"kumachan/interpreter/lang/textual/parser"
	"kumachan/interpreter/lang/textual/syntax"
	"kumachan/interpreter/lang/textual/transformer"
)


func CraftThunk(mod manifest.Module, path string, tree *ast.Root) ModuleThunk {
	return ModuleThunk {
		ModPath:  path,
		FileInfo: craftModuleFileInfo(filepath.Base(path)),
		Manifest: mod,
		Content:  PredefinedAST { tree },
	}
}

func CraftEmptyThunk(mod manifest.Module, path string) ModuleThunk {
	var root = craftEmptyAST(path)
	return CraftThunk(mod, path, &root)
}

func craftEmptyAST(cst_name string) ast.Root {
	var root = syntax.DefaultRootPartName
	var empty_cst, err = parser.Parse(([] rune)(""), root, cst_name)
	if err != nil { panic("something went wrong") }
	var empty_ast = transformer.Transform(empty_cst)
	return empty_ast.(ast.Root)
}

func craftModuleFileInfo(name string) os.FileInfo {
	return craftedFileInfo {
		name: name,
	}
}


